package cn.jbit.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jbit.news.dao.NewsDao;
import org.jbit.news.dao.UserDao;
import org.jbit.news.dao.impl.NewsDaoImpl;
import org.jbit.news.dao.impl.UserDaoImpl;
import org.jbit.news.entity.News;
import org.jbit.news.entity.User;

@SuppressWarnings("serial")
public class do_login extends HttpServlet{

	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setContentType("text/html;charset=UTF-8");
		String uname=req.getParameter("uname");
		String upwd=req.getParameter("upwd").trim();
		UserDao userDao=new UserDaoImpl();
	    User user =userDao.findUser(uname,upwd);
		PrintWriter out=resp.getWriter();
		if(user!=null){
//			NewsDao newsDao=new NewsDaoImpl();
//			List<News> list=newsDao.getAllnews();
			req.getSession().setAttribute("uname",uname);
			resp.sendRedirect("newspages/admin.jsp");
		}else{
			out.print(
					"<script type='text/javascript'>alert('登陆失败!!!!');location.href='index.jsp';</script>");
			out.close();
		}
	}
	public void destroy() {
		super.destroy();
	}

	public void init(ServletConfig config) throws ServletException {
		super.init(config);
	}

}
